package com.intellagric.service.traceability.Impl.trace_record_table;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.mapper.TraceTableRowsMapper;
import com.intellagric.module.traceability.CheckRecordVo;
import com.intellagric.pojo.TraceRecordCheck;
import com.intellagric.pojo.TraceTable;
import com.intellagric.pojo.TraceTableRows;
import com.intellagric.pojo.TraceTableRowsExample;
import com.intellagric.service.traceability.trace_record_table.TableRowsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2019/2/21
 * @DESC： 表格列数据服务接口
 */
@Service
public class TableRowsServiceImpl implements TableRowsService{

    @Autowired
    private TraceTableRowsMapper tableRowsMapper;

    /**
     * 添加列
     * @param tableRows
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage addTableRows(TraceTableRows tableRows) {
        if (tableRowsMapper.insertSelective(tableRows) == 1 ) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 删除列
     * @param id
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage deleteTableRows(String id) {
        if (tableRowsMapper.deleteByPrimaryKey(id) == 1 ) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 修改列
     * @param tableRows
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage editTableRows(TraceTableRows tableRows) {
        if (tableRowsMapper.updateByPrimaryKeySelective(tableRows) == 1 ) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 根据tableid查询列
     * @param tableId
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getTableRowsBytableId(String tableId) {
        TraceTableRowsExample tableRowsExample = new TraceTableRowsExample();
        tableRowsExample.setOrderByClause("size");
        tableRowsExample.createCriteria().andTableIdEqualTo(tableId);
        List<TraceTableRows> tableRowsList = tableRowsMapper.selectByExample(tableRowsExample);
        return LayuiDataGridResult.success().add(tableRowsList,tableRowsList.size());
    }

    /**
     * 查询列列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getTablesRowsList() {
        return null;
    }

    @Override
    public LayuiDataGridResult getTableRowsPage(int page, int rows) {
        return null;
    }

    @Override
    public LayuiDataGridResult getTableRowsPageByVo(int page, int rows, TraceTableRows tableRows) {
        return null;
    }
}
